from wcs.libs.players import players
from wcs.libs.items import items

itemName = 'Scroll of Respawning'
item = items.addItem(itemName)
item.setGroup("special")
item.setCost(5000)
item.setDescription("""This sroll has a magical inscription to bring you back
to life after you die. Lasts until you die.""")
item.setMaxCount(1)
item.permanent = True
        
def player_death(event_var):
    """
    Executed when a player dies, if they had this item, then respawn them.
    """
    userid = event_var["userid"]
    player = players[userid]
    if player.getItem(itemName).count:
        player.spawn()
        player.removeItem(itemName)